package com.cssw.fyzb.core.util;

import java.math.BigDecimal;

/**
 * @Author: chenchao
 * @Date: 2020/8/4 14:35
 */
public class BigDecimalUtl {

    public static BigDecimal parseToBdl(String s) {
        if (s == null) {
            return null;
        }

        return BigDecimal.valueOf(Double.parseDouble(s));

    }

    public static boolean isBigDecimal(String str) {
        if (str == null || str.trim().length() == 0) {
            return false;
        }
        char[] chars = str.toCharArray();
        int sz = chars.length;
        int i = (chars[0] == '-') ? 1 : 0;
        if (i == sz) return false;

        if (chars[i] == '.') return false;//除了负号，第一位不能为'小数点'

        boolean radixPoint = false;
        for (; i < sz; i++) {
            if (chars[i] == '.') {
                if (radixPoint) return false;
                radixPoint = true;
            } else if (!(chars[i] >= '0' && chars[i] <= '9')) {
                return false;
            }
        }
        return true;
    }

    /**
     * 大于 0 判断
     *
     * @return
     */
    public static boolean isGreaterThanZero(BigDecimal num) {
        if (num == null) {
            return false;
        }
        return num.compareTo(BigDecimal.ZERO) > 0;
    }

    /**
     * 大于等于 0 判断
     *
     * @return
     */
    public static boolean isGreaterThanEqualsZero(BigDecimal num) {
        if (num == null) {
            return false;
        }
        return num.compareTo(BigDecimal.ZERO) >= 0;
    }

    public static void main(String arg[]) {
        BigDecimal num = BigDecimal.ZERO;
        System.out.println(isGreaterThanEqualsZero(num));
    }

}
